// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Author: Markus Gutschke

#ifndef CONNECTION_H__
#define CONNECTION_H__

#include <sys/types.h>
#include <sys/uio.h>

#include "ssl.h"


struct Connection {
  int              fd;
  struct SSL       *ssl;
  struct SSLHandle *handle;
  char             *buf;
  size_t           offset, sz;
};

struct Connection *newConnection(int fd);
void initConnection(struct Connection *conn, int fd);
void destroyConnection(struct Connection *conn);
void deleteConnection(struct Connection *conn);
void upgradeConnection(struct Connection *conn);
int connectionIsSecure(struct Connection *conn);
int connIsReadable(struct Connection *conn, int timeout);
int connIsWriteable(struct Connection *conn, int timeout);
ssize_t connRead(struct Connection *conn, char *buf, size_t sz);
ssize_t connReadTMO(struct Connection *conn, char *buf, size_t sz, int tmo);
ssize_t connReadAll(struct Connection *conn, char *buf, size_t sz);
ssize_t connReadAllTMO(struct Connection *conn, char *buf, size_t sz, int tmo);
ssize_t connPeek(struct Connection *conn, char *buf, size_t sz);
ssize_t connWrite(struct Connection *conn, const char *buf, size_t sz);
ssize_t connWriteTMO(struct Connection *conn, const char *buf, size_t sz,
                     int tmo);
ssize_t connWriteV(struct Connection *conn, struct iovec *io, int cnt);
ssize_t connWriteVTMO(struct Connection *conn, struct iovec *io, int cnt,
                      int tmo);

#endif  // CONNECTION_H__
